package cn.news.control;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import cn.news.biz.PressBiz;
import cn.news.entity.Press;


public class AdminPressServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
   
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;Charset=utf-8");
		HttpSession session=request.getSession();
		int tid=Integer.parseInt(request.getParameter("tid"));
		int uid=Integer.parseInt(request.getParameter("uid"));
		PrintWriter out=response.getWriter();
		String ptime=request.getParameter("ptime");
		SimpleDateFormat sd=new SimpleDateFormat("yyyy-MM-dd");
		Date dtime=null;
		
			try {
				dtime = sd.parse(ptime);
			} catch ( Exception e) {
				
				e.printStackTrace();
			}
		
		String title=request.getParameter("title");
		Press press=new Press(title,dtime,uid,tid);
		PressBiz pBiz=new PressBiz();
		if(pBiz.addPress(press)){
			
			request.getRequestDispatcher("press.jsp").forward(request, response);
		}else{
			out.print("新增失败");
		}
		
	}
	

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
